function [B, K] = getpareto(A)
%B = GETPARETO(A)
%   Returns the pareto points of A, that is, the points
%   for which there is no other point that is better in
%   any dimension without being worse in another.
%   A and B are 2-d matrices with a measurement in each row.
%   [B, K] = GETPARETO(A) also returns a vector K such that
%   B = A(K)

if iscell(A)
  A = cell2mat(A(:, 1:end-1));
end

[A, I, J] = uniquerowsdesc(A);

B = [];
K = [];
for i = 1:size(A, 1)
  p = 1;
  for j = 1:size(A, 1)
    if i ~= j & all(A(j, :) <= A(i, :))
      p = 0;
      break
    end
  end

  if p == 1
    B(size(B, 1)+1, :) = A(i, :);
    K = [K; I(i)];
  end
end
